<?php
// +----------------------------------------------------------------------
// | 奇乐中介担保交易系统 免费版 2019
// +----------------------------------------------------------------------
// | 官方网址：http://www.qilecms.com   
// +----------------------------------------------------------------------
// | 产品文档：http://www.qilecms.com/doc
// +----------------------------------------------------------------------
// | 开发作者:奇乐CMS
// +----------------------------------------------------------------------
// | 版权说明：这不是一个自由软件！本产品仅限个人使用，但请务必保留底部版权，以免产生不必要的纠纷,
// | 您只能在不用于商业目的的前提下对程序代码进行修改和使用，
// | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
// +----------------------------------------------------------------------
namespace app\guarantee\controller;
class Notice extends Base
{
 
  protected $beforeActionList = [
        'iniCate',

    ];
     protected function iniCate()
    {
     $param = $this->request->param();
       //获得所有分类
      $cate =  model('noticeCategory')->listData();
      $cateTree  = list_to_tree($cate,'cid');
      $cateinfo =[];
      foreach($cateTree as $k=>$v){
        $cateinfo[$v['alias']] =$v;
      } 
    $type = $param['type1'];  //一级分类
    $this->cate = $cateinfo[$type];  //当前分类

    
    $this->assign('cateData',$cateinfo[$type]);


    }
    public function list()
    {
      $param = $this->request->param();
     
      $type = $param['type1'];  //一级分类
      //获得所有分类
      $cate =  model('noticeCategory')->listData();
      $cateTree  = list_to_tree($cate,'cid');

      $cateinfo =[];
      foreach($cateTree as $k=>$v){
        $cateinfo[$v['alias']] =$v;

      }
      $list =$cateinfo[$type]['children'];

      foreach($list as $k=>$v){
        $map['cid'] = $v['cid'];
        $article_list = model('info')->listData($map);
        $list[$k]['article_list'] = $article_list;
      }

//获得文章信息
      if($param['id']){
          $where['id'] = intval($param['id']);
          $notice = model('notice')->infoData($where);
          $this->assign('notice',$notice);

          //更新文章点击量
          model('notice')->where($where)->setInc('hits',1);
      }else{
        //调用所有文章最新的
     
        $cids = $this->cate['cid'].get_children_ids('noticeCategory',$this->cate['cid'],"pid","cid");
        $map2 = "cid IN ($cids)";
        $notice_lists = model('notice')->listPageData($map2,'','create_time desc',10);
        $notice_list =$notice_lists->toArray()['data'];
        $page = $notice_lists->render();
        
       
        $this->assign('notice_list',$notice_list);
        $this->assign('page',$page);

      }
     
      // 模板变量赋值
      $this->assign('list', $list);
      $this->assign('cateData',$cateinfo[$type]);
      return $this->fetch('index');
    }

}